function querygame() {
    var prizeNames=""
    if($("#prizeName option:selected").text()=="请选择奖品"){
        prizeNames=""
    }else {
        prizeNames=$("#prizeName option:selected").text()
    }

    var beginTimes=""
    if($("#beginTime").val()!=""){
        beginTimes=$("#beginTime").val()+' '+'00:00:00'
    }else {
        beginTimes=""
    }
    var endTimes=""
    if($("#endTime").val()!=""){
        endTimes=$("#endTime").val()+' '+'23:59:59'
    }else {
        endTimes=""
    }
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/listWinPrizeCustomer',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "pageNum":"1",
            "pageSize":"50",
            "activityId":sessionStorage.getItem("activityids"),
            "loginAccount":$("#loginAccount").val(),
            "telephone":$("#telephone").val(),
            "prizeName":prizeNames,
            "winCode":$("#winCode").val(),
            "prizeDisplayName":$("#prizeDisplayName").val(),
            "beginTime":beginTimes,
            "endTime":endTimes,
            "isProvide":$("#isProvide option:selected").val(),
        }),
        success: function (data) {
            var pk=""
            if(data.data.result!=null){
                pk=data.data.totalPage
                couponlist1(data.data.result);
            }else {
                couponlist1("");
                pk=0
            }
            $('.M-box3').pagination({
                pageCount:pk,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    console.log(api)
                    $.ajax({
                        url: 'https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/listWinPrizeCustomer',
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":50,
                            "activityId":sessionStorage.getItem("activityids"),
                            "loginAccount":$("#loginAccount").val(),
                            "telephone":$("#telephone").val(),
                            "prizeName":prizeNames,
                            "winCode":$("#winCode").val(),
                            "prizeDisplayName":$("#prizeDisplayName").val(),
                            "beginTime":beginTimes,
                            "endTime":endTimes,
                            "isProvide":$("#isProvide option:selected").val(),
                        }),
                        success: function (result) {
                            couponlist1(result.data.result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
function couponlist1(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    $.each(data, function (i, field) {
        var rowData = new Array();
        rowData.push(field.activityId);
        rowData.push(field.loginAccount);
        rowData.push(field.winCode);
        rowData.push(field.telephone);
        rowData.push(field.prizeName);
        rowData.push(field.prizeDisplayName);
        rowData.push(field.createTime);
        rowData.push(field.isProvide);
        dataSource.push(rowData);

    });

    initData(dataSource);

    function initData(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "autoWidth": false,
            "order": [[ 7, "desc" ]],
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": false,
            "destroy": false,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu":[10,20,30],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[3]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets":3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[4]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[5]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[6]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ""
                        if (row[7] ==10) {
                            val = '是'
                        }else if (row[7] ==20){

                            val='<span class="dropDown"> <a class="dropDown_A " data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">否<i class="Hui-iconfont">&#xe6df;</i></a><ul class="dropDown-menu menu radius box-shadow"><li onclick="fafang(2,\'' + row[2] + '\')"><a href="#">是</a></li></ul></span>'
                        }
                        return val;
                    },
                    "targets": 7
                },


            ]
        });

    };
}
//导出
function daochu() {
    var ets=""
    var bts=""
            let endTime = ($("#endTime").val()).replace(/-/g, '/');
            let beginTime = ($("#beginTime").val()).replace(/-/g, '/');
            if($("#endTime").val()==""){
                ets=""
            }else {
                ets="&endTime="+endTime
            }
            if($("#beginTime").val()==""){
                bts=""
            }else {
                bts="&beginTime="+beginTime
             }
            $('#form_dsubbmit').attr('href','https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/downloadWinPrizeCustomer'+"?activityId="+sessionStorage.getItem("activityids")+"&loginAccount="+$("#loginAccount").val()
                +"&telephone="+$("#telephone").val()+"&prizeName="+$("#prizeName option:selected").val()+"&winCode="+$("#winCode").val()+"&prizeDisplayName="+$("#prizeDisplayName").val()+bts
                + ets+"&isProvide="+$("#isProvide option:selected").val()
            );

}


//全部发放
function fafang(val,winCodes) {
if(val==1){
    var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >确定要全部发放吗？</span>', {title:'提示',btn: ['确定', '取消']}, function(index){

        $.ajax({
            url: 'https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/allIssued',
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            contentType: "application/json",
            data: JSON.stringify({
                "activityId":sessionStorage.getItem("activityids"),
                "loginAccount":$("#loginAccount").val(),
                "telephone":$("#telephone").val(),
                "prizeName":$("#prizeName option:selected").val(),
                "winCode":$("#winCode").val(),
                "prizeDisplayName":$("#prizeDisplayName").val(),
                "beginTime":$("#beginTime").val(),
                "endTime":$("#endTime").val(),
                "isProvide":$("#isProvide option:selected").val(),
            }),
            success: function (data) {
                if(data.errorCode==0){
                    querygame()
                }else {
                    $.Huimodalalert(data.message,2000);
                }
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        });
        layer.close(curInd);
    },function(){
        layer.close(curInd);

    });

}else {
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/apromotion/lotteryDraw/allIssued',
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "activityId":sessionStorage.getItem("activityids"),
            "loginAccount":$("#loginAccount").val(),
            "telephone":$("#telephone").val(),
            "prizeName":$("#prizeName option:selected").val(),
            "winCode":winCodes,
            "prizeDisplayName":$("#prizeDisplayName").val(),
            "beginTime":$("#beginTime").val(),
            "endTime":$("#endTime").val(),
            "isProvide":$("#isProvide option:selected").val(),
        }),
        success: function (data) {
            if(data.errorCode==0){
                querygame()
            }else {
                $.Huimodalalert(data.message,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}


}